<%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 04/06/2018
  Time: 9:48 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.Connection" contentType="text/html;charset=utf-8" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.Statement" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


    <title>注册页面</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
<br>
<%
    request.setCharacterEncoding("utf-8");
    String users = request.getParameter("username");
    String pass = request.getParameter("pwd");
%>
<%
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/livinginzhuhai";
    String use = "root";
    String password = "12345678c";
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, use, password);
    Statement stmt = conn.createStatement();
    if (stmt.executeQuery("SELECT * FROM user WHERE id='" + users + "'").next()) { %>
<script type="text/JavaScript">
    alert("账号已经存在");
    window.history.back(-1);
</script>
<% } else {
    PreparedStatement sql = conn.prepareStatement("insert into user(id,pwd)values(?,?)");
    sql.setString(1, users);
    sql.setString(2, pass);
    int rtn = sql.executeUpdate();
    sql.close();
    conn.close();%>
<jsp:forward page="index.jsp"/>
<%
    }
%>
</body>
</html>